<ui:composition xmlns="http://www.w3.org/1999/xhtml"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:h="http://java.sun.com/jsf/html"
	template="../../Template/TemplateAdmin.xhtml"
	xmlns:c="http://java.sun.com/jsp/jstl/core"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:rich="http://richfaces.org/rich">


	<ui:define name="title">
		Trang Quản lý bình luận
  	</ui:define>


	<ui:define name="content">

		<h:outputScript library="js" name="TrangQuanLyBinhLuan.js"
			target="head" />
		<!-- Content -->
		<div id="MainPanel" align="left">

			<div class="ContentPart">
				<h1 class="ContentPartTitle" align="center">TRANG QUẢN LÝ BÌNH
					LUẬN</h1>
			</div>
			<div class="ContentPart">
				<h3 class="ContentPartHeader">Thao tác</h3>
				<div class="ContentPartContent">
					<div id="rightAction" align="right">
						<h:commandLink immediate="true"
							action="#{quanLyBinhLuanBean.LietKeToanBo()}">
							<div class="actionWideButtonRight" align="center">
								<img class="buttonImage imgNoBackgroundBorder"
									src="../../Images/Icon/icon_lietKeLarge.png" alt="Liệt kê" />
								<div class="buttonCaption">Liệt kê toàn bộ</div>
							</div>
							<f:ajax render="tableContentBinhLuan" />
						</h:commandLink>
					</div>
					<div id="leftAction">

						<div class="ins">Tìm kiếm Sản phẩm:</div>
						<div id="Search">
							<h:inputText id="inputTim" class="txtField" type="text"
								value="#{quanLyBinhLuanBean.chuoiTimKiem}" />
							<h:commandLink action="#{quanLyBinhLuanBean.TimKiemSanPham()}"
								outcom="TrangQuanLyDonDatHang">
								<div id="btSearch">Tìm</div>
							</h:commandLink>
						</div>
						<hr />
						<div class="ins">Liệt kê Đơn hàng:</div>
						<div class="Filter">
							<!-- &nbsp;&nbsp;  -->
							<label for="cbbNhomSanPham">Nhóm SP: </label>

							<h:selectOneMenu name="cbbNhomSanPham" id="cbbNhomSanPham"
								class="combobox" value="#{quanLyBinhLuanBean.maNhomLietKe}">
								<f:selectItem itemValue="-1" itemLabel="Tất cả" />
								<f:selectItems value="#{headerBean.lstDanhMuc}" var="danhMuc"
									itemLabel="#{danhMuc.getTennhom()}"
									itemValue="#{danhMuc.getManhom()}" />
								<f:ajax listener="#{quanLyBinhLuanBean.changeNhomListener}"
									render="cbbLoaiSanPham" />
							</h:selectOneMenu>
							<br /> <label for="cbbLoaiSanPham">Loại Sản phẩm: </label>
							<h:selectOneMenu name="cbbLoaiSanPham" id="cbbLoaiSanPham"
								class="combobox" value="#{quanLyBinhLuanBean.maLoaiLietKe}">
								<f:selectItems value="#{quanLyBinhLuanBean.lstLoaiSanPham}"
									var="danhMucLoaiSanPham"
									itemLabel="#{danhMucLoaiSanPham.getTenloaisanpham()}"
									itemValue="#{danhMucLoaiSanPham.getMaloaisanpham()}" />
							</h:selectOneMenu>
							<br /> <label for="cbbTrangThaiDuyet"><span class="bold">Trạng
									thái:</span> Duyệt: </label>
							<h:selectOneMenu name="cbbTrangThaiDuyet" id="cbbTrangThaiDuyet"
								class="combobox" value="#{quanLyBinhLuanBean.trangThaiDuyet}">
								<f:selectItem itemValue="-1" itemLabel="Tất cả" />
								<f:selectItem itemValue="0" itemLabel="Chưa duyệt" />
								<f:selectItem itemValue="1" itemLabel="Đã duyệt" />
							</h:selectOneMenu>
							-- <label for="cbbTrangThaiXoa">Xóa: </label>
							<h:selectOneMenu name="cbbTrangThaiXoa" id="cbbTrangThaiXoa"
								class="combobox" value="#{quanLyBinhLuanBean.trangThaiXoa}">
								<f:selectItem itemValue="-1" itemLabel="Tất cả" />
								<f:selectItem itemValue="0" itemLabel="Chưa xóa" />
								<f:selectItem itemValue="1" itemLabel="Đã xóa" />
							</h:selectOneMenu>
							<h:commandLink action="#{quanLyBinhLuanBean.LietKeTheoNhuCau()}"
								outcom="TrangQuanLyDonDatHang">
								<div id="btFilter">Liệt Kê</div>
							</h:commandLink>
						</div>
					</div>
				</div>
			</div>

			<div class="ContentPart">
				<div class="ContentPartContent">
					<h:messages id="messageNotification" />
				</div>
			</div>
			<!-- Content 1-->
			<div class="ContentPart">
				<h3 class="ContentPartHeader pointerCursor"
					onclick="return ShowHidePanelSanPham();">Danh sách sản phẩm</h3>
				<h:panelGroup id="tableContentSanPham">
					<h:dataTable value="#{quanLyBinhLuanBean.lstSanPham}" var="sp"
						styleClass="tableDulieu"
						rendered="#{not empty quanLyBinhLuanBean.lstSanPham}"
						rowClasses="rowLe,rowChan">

						<ui:param name="index"
							value="#{quanLyBinhLuanBean.lstSanPham.indexOf(sp)}" />

						<h:column>
							<f:facet name="header">STT</f:facet>
							<h:outputText value="#{index + 1}" />
						</h:column>
						<h:column>
							<f:facet name="header">Mã SP</f:facet>
							<h:commandLink action="#">#{sp.masanpham}</h:commandLink>
						</h:column>
						<h:column>
							<f:facet name="header">Tên SP</f:facet>
							<h:commandLink action="#">#{sp.tensanpham}</h:commandLink>
						</h:column>
						<h:column>
							<f:facet name="header">Loại SP</f:facet>
							<h:outputText value="#{sp.loaisanpham.tenloaisanpham}" />
						</h:column>
						<h:column>
							<f:facet name="header">Nhà SX</f:facet>
							<h:outputText value="#{sp.nhasanxuat.tennhansanxuat}" />
						</h:column>
						<h:column>
							<f:facet name="header">Xuất xứ</f:facet>
							<h:outputText value="#{sp.xuatxu}" />
						</h:column>
						<h:column>
							<f:facet name="header">Ngày Nhận</f:facet>
							<h:outputText value="#{sp.ngaynhansanpham}" />
						</h:column>
						<h:column>
							<f:facet name="header">Số lượng bán / còn</f:facet>
							<h:outputText value="#{sp.soluongban} / #{sp.soluongtrongkho}" />
						</h:column>
						<h:column>
							<f:facet name="header">Giá</f:facet>
							<h:outputText value="#{sp.giaban}" styleClass="tien-te">
								<f:convertNumber groupingUsed="true" pattern="#0,000" />
							</h:outputText>
						</h:column>
						<h:column>
							<f:facet name="header">Xóa</f:facet>
							<h:outputText value="Xóa" rendered="#{sp.daxoa}" />
							<h:outputText value="Chưa" rendered="#{not sp.daxoa}" />
						</h:column>
						<h:column>
							<f:facet name="header">Thao tác</f:facet>
							<div class="thaoTacCol">
								<h:commandButton
									class="acceptIcon no-border pointerCursor flowToLeft"
									process="@this" immediate="true"
									onclick="if (confirm ('Bạn có chắc chắc muốn tìm Bình luận tương ứng Sản phẩm này?')){$(this).addClass('selectedRow');return true;}return false;"
									action="#{quanLyBinhLuanBean.TimKiemBinhLuan(sp)}"
									outcome="TrangQuanLyBinhLuan" alt="Tìm Bình luận" />

							</div>
						</h:column>
					</h:dataTable>
				</h:panelGroup>
			</div>
			<!-- Content 2 -->
			<div class="ContentPart">
				<h3 class="ContentPartHeader pointerCursor"
					onclick="return ShowHidePanelBinhLuan();">Danh sách Bình luận</h3>
				<h:panelGroup id="tableContentBinhLuan">
					<h:dataTable value="#{quanLyBinhLuanBean.lstBinhLuan}" var="bl"
						styleClass="tableDulieu"
						rendered="#{not empty quanLyBinhLuanBean.lstBinhLuan}"
						rowClasses="rowLe,rowChan">

						<ui:param name="index"
							value="#{quanLyBinhLuanBean.lstBinhLuan.indexOf(bl)}" />

						<h:column>
							<f:facet name="header">STT</f:facet>
							<h:outputText value="#{index + 1}" />
						</h:column>
						<h:column>
							<f:facet name="header">Mã B.luận</f:facet>
							<h:commandLink action="#">#{bl.mabinhluan}</h:commandLink>
						</h:column>
						<h:column>
							<f:facet name="header">Người viết</f:facet>
							<h:commandLink action="#">#{bl.taikhoan.hoten}</h:commandLink>
						</h:column>
						<h:column>
							<f:facet name="header">Sản phẩm</f:facet>
							<h:commandLink action="#">#{bl.sanpham.tensanpham}</h:commandLink>
						</h:column>
						<h:column>
							<f:facet name="header">Ngày viết</f:facet>
							<h:outputText value="#{bl.ngayviet}" />
						</h:column>
						<h:column>
							<f:facet name="header">Đánh giá</f:facet>
							<h:outputText value="#{bl.danhgia} sao" />
						</h:column>
						<h:column>
							<f:facet name="header">Duyệt</f:facet>
							<h:outputText value="Duyệt" rendered="#{bl.daduyet}" />
							<h:outputText value="Chưa" rendered="#{not bl.daduyet}" />
						</h:column>
						<h:column>
							<f:facet name="header">Xóa</f:facet>
							<h:outputText value="Xóa" rendered="#{bl.daxoa}" />
							<h:outputText value="Chưa" rendered="#{not bl.daxoa}" />
						</h:column>
						<h:column>
							<f:facet name="header">Thao tác</f:facet>
							<h:commandButton
								class="deleteIcon no-border pointerCursor flowToLeft"
								process="@this" immediate="true"
								onclick="if (confirm ('Bạn có chắc chắc muốn xóa Bình luận này?')) return true; return false;"
								action="#{quanLyBinhLuanBean.Xoa(bl)}"
								outcome="TrangQuanLyBinhLuan" alt="Xóa"
								rendered="#{not bl.daxoa}" />
							<h:commandButton
								class="editIcon no-border pointerCursor flowToLeft"
								immediate="true" onclick="setTimeout(ShowEditDialog,2500);"
								action="#{quanLyBinhLuanBean.SetMaBinhLuanAndGetData(bl.mabinhluan)}"
								alt="Sửa">
								<f:ajax execute="@this" render="@form" />
							</h:commandButton>
							<h:commandButton
								class="acceptIcon no-border pointerCursor flowToLeft"
								process="@this" immediate="true"
								onclick="if (confirm ('Bạn có chắc chắc muốn Hủy xóa Bình luận này?')) return true; return false;"
								action="#{quanLyBinhLuanBean.HuyXoa(bl)}"
								outcome="TrangQuanLyBinhLuan" alt="Hủy Xóa"
								rendered="#{bl.daxoa}" />
							<h:commandButton
								class="acceptIcon no-border pointerCursor flowToLeft"
								process="@this" immediate="true"
								onclick="if (confirm ('Bạn có chắc chắc muốn Duyệt hiển thị Bình luận này?')) return true; return false;"
								action="#{quanLyBinhLuanBean.Duyet(bl)}"
								outcome="TrangQuanLyBinhLuan" alt="Duyệt"
								rendered="#{not bl.daduyet and not bl.daxoa}" />
							<h:commandButton
								class="deleteIcon no-border pointerCursor flowToLeft"
								process="@this" immediate="true"
								onclick="if (confirm ('Bạn có chắc chắc muốn Hủy duyệt Bình luận này?')) return true; return false;"
								action="#{quanLyBinhLuanBean.HuyDuyet(bl)}"
								outcome="TrangQuanLyBinhLuan" alt="Hủy Duyệt"
								rendered="#{bl.daduyet and not bl.daxoa}" />
						</h:column>
					</h:dataTable>
				</h:panelGroup>
			</div>
		</div>
		<!-- Content -->

		<h:outputScript library="js" name="TrangQuanLyBinhLuan.js"
			target="head" />

		<div id="editBinhLuan" class="hidden">
			<p>Mã bình luận</p>
			<h:outputText value="#{quanLyBinhLuanBean.maBinhLuan}" />
			<p>Nội dung</p>
			<h:inputTextarea value="#{quanLyBinhLuanBean.noiDungBinhLuan}" />
			<br/><br/>
			<h:commandButton class="dialogButton buttonLink button" value="Sửa"
				action="#{quanLyBinhLuanBean.SuaBinhLuan()}" />
		</div>
		<!-- Dialog -->
	</ui:define>
</ui:composition>